package com.lixw.study.controller;

import com.lixw.study.entity.User;
import com.lixw.study.resp.ResultData;
import com.lixw.study.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: UserController
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/7/31 09:48
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping
    public ResultData<Boolean> addUser(@RequestBody User user) {
        boolean flag = userService.save(user);
        return ResultData.success(flag);
    }

    @GetMapping("/{id}")
    public ResultData<User> getUser(@PathVariable Integer id) {
        User user = userService.getById(id);
        return ResultData.success(user);
    }

    @PutMapping
    public ResultData<Boolean> updateUser(@RequestBody User user) {
        boolean flag = userService.updateById(user);
        if(flag){
            return ResultData.success(true);
        }else{
            return ResultData.success(false);
        }
    }
}